home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / disp_txt.pro < prev    next >
Text File  |  1997-07-08  |  22KB  |  506 lines

  1. ; $Id: disp_txt.pro,v 1.3 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ; Copyright (c) 1992-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;
  6. ;+
  7. ; NAME:
  8. ;    DISP_TXT
  9. ;
  10. ; PURPOSE:
  11. ;    This procedure displays text strings in the current IDL window.
  12. ;       The text strings may contain control sequences which define
  13. ;       what font, color, and position to use when drawing the text.
  14. ;
  15. ; CATEGORY:
  16. ;    Text Display.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;       DISP_TXT, Strings, Fonts, Yspace
  20. ;
  21. ; INPUTS:
  22. ;       Strings:    A string or string array containing the text to
  23. ;                   display in the current IDL window.   The string(s)
  24. ;                   may contain control sequences which specify what
  25. ;                   font, color, and position to use when drawing the text.
  26. ;                   Control sequences are enclosed in back quotes.
  27. ;                   Control sequences consist of one or more commands
  28. ;                   separated by commas.   Commands start with one of
  29. ;                   the following upper or lower case characters :
  30. ;
  31. ;                   F  -  Specify a new font to use
  32. ;                   C  -  Specify a new color to use
  33. ;                   J  -  Specify a new justification (alignment)
  34. ;                   X  -  Specify a new absolute X position (in pixels)
  35. ;                   Y  -  Specify a new absolute Y position (in pixels)
  36. ;                   H  -  Shift horizontally a relative amount (in pixels)
  37. ;                   V  -  Shift vertically a relative amount (in pixels)
  38. ;
  39. ;                   Here is an example of a text string with an imbedded
  40. ;                   control sequence to change to font #2, color #255,
  41. ;                   justification 0.5 (center), and absolute Y position 100 :
  42. ;
  43. ;                      ABCDEF`F2,C255,J0.5,Y100`GHIJKL
  44. ;
  45. ;                   The actual fonts to use are specified by the "Fonts"
  46. ;                   parameter (see below).
  47. ;
  48. ;                   Care must be taken when specifying any justification
  49. ;                   other than 0.0 (left justify) or the strings may overlap.
  50. ;                   A good rule of thumb is if center justification (0.5) or
  51. ;                   right justification (1.0) is desired, then put the
  52. ;                   control commands before or after a block of text, but
  53. ;                   not in the middle of it.
  54. ;
  55. ;                   One line of text is output for each non-null element
  56. ;                   in "Strings".   If an element in "Strings" is null
  57. ;                   or contains only a control seqence, then no new line
  58. ;                   is output.   To output a blank line, use a space
  59. ;                   character on a line by itself.
  60. ;                   Data Type : String or Strarr.
  61. ;
  62. ;       Fonts:      A string or string array containing the font(s) to
  63. ;                   use.   When a command of the form "Fn" is encountered
  64. ;                   while processing the text, the nth element of "Fonts"
  65. ;                   is passed to the "Device, Font=" command.   Using the
  66. ;                   above example, when the "F2" command is processed,
  67. ;                   the font is set by automatically issuing the command :
  68. ;
  69. ;                      Device, Font=Fonts(2)
  70. ;
  71. ;                   IF the specified font number is less than zero, or
  72. ;                   greater than or equal to the number of elements in
  73. ;                   "Fonts", then Fonts(0) is used.
  74. ;
  75. ;                   Fonts may be specified using wildcards, and may have
  76. ;                   an optional field that specifies what style of vector
  77. ;                   drawn font to use if the specified hardware font does
  78. ;                   not exist.   The optional field is separated from the
  79. ;                   actual font string by a "|" character.   (The optional
  80. ;                   field is always stripped off before passing the string
  81. ;                   to the "Device, Font=" command.)   An example of a
  82. ;                   "Fonts" array is as follows :
  83. ;
  84. ;                      *helvetica-bold*--12*|10!5
  85. ;                      vector|20!3
  86. ;                      *helvetica-bold*--24*
  87. ;
  88. ;                   This example array specifies the following :
  89. ;
  90. ;                   0. Use 12 point helvetica bold hardware font for font F0.
  91. ;                      If no matching font exists on the current system
  92. ;                      then use vector font style #5 (duplex roman), and size
  93. ;                      the font so that it is 10 pixels high.   For a list of
  94. ;                      the IDL vector drawn fonts, see chapter 12 in the IDL
  95. ;                      User's Guide.
  96. ;                   1. Since there is no such thing as a hardware font called
  97. ;                      "vector", then use a software (vector drawn) font for
  98. ;                      font F1.   Draw this font 20 pixels high and use font
  99. ;                      style #3 (simplex roman).
  100. ;                   2. Use 24 point helvetica bold hardware font for font F2.
  101. ;                      If no matching font exists on the current system
  102. ;                      then use the most recently specified vector drawn font
  103. ;                      (since there is no optional field specified for this
  104. ;                      font).
  105. ;
  106. ;                   On some Unix systems, it is possible to list the available
  107. ;                   hardware fonts by using the Unix command "xlsfonts".
  108. ;
  109. ;                   When running under Windows or MacOS, fonts are specified
  110. ;                   in a slightly different manner.   For example, a Helvetica
  111. ;                   italic 24-point font could be specified by the font
  112. ;                   definition :
  113. ;
  114. ;                      HELVETICA*ITALIC*24
  115. ;
  116. ;                   For best results, use a scalable font.
  117. ;
  118. ;                   See "The Windows Device Driver" in the "IDL For Windows"
  119. ;                   document.
  120. ;
  121. ;                   Data Type : String or Strarr.
  122. ;
  123. ;       Yspace:     The spacing, in pixels, between the baseline of each
  124. ;                   line of text.   IF "Yspace" is negative then the baseline
  125. ;                   of each line of text will be Yspace pixels ABOVE the
  126. ;                   previous line.   Otherwise, each line is placed Yspace
  127. ;                   pixels BELOW the previous line.
  128. ;                   Data Type : Int or Long.
  129. ;
  130. ; KEYWORD PARAMETERS:
  131. ;       Xstart:     The X location (in pixels) at which to start drawing
  132. ;                   the text.
  133. ;                   The default is to start near the left edge of the current
  134. ;                   window (unless the default justification is Center or
  135. ;                   Right, in which case the default starting X location is
  136. ;                   set accordingly).
  137. ;                   Data Type : Int or Long.
  138. ;       Ystart:     The Y location (in pixels) at which to start drawing
  139. ;                   the text.
  140. ;                   The default is to start near the top edge of the current
  141. ;                   window.   (Unless "Yspace" is negative, in which case the
  142. ;                   default is to start near the bottom edge of the current
  143. ;                   window).
  144. ;                   Data Type : Int or Long.
  145. ;       Def_Font:   The font to use when no font has been specified in
  146. ;                   "Strings".   "Def_Font" is specified just like the fonts
  147. ;                   in "Fonts" (except that no optional field should be used).
  148. ;                   If no font is specified in "Strings" and "Def_Font" is
  149. ;                   not supplied, then the default is to use the default
  150. ;                   hardware font.   If no hardware font is available then
  151. ;                   use a vector drawn font as the default.
  152. ;                   Data Type : String.
  153. ;
  154. ;       Def_Size:   The default height (in pixels) of the vector drawn font.
  155. ;                   The default is !D.Y_CH_SIZE.
  156. ;                   Data Type : Int or Long.
  157. ;
  158. ;       Def_Style:  The default style (such as !3, !4, etc.) of the vector
  159. ;                   drawn font.
  160. ;                   The default is '!3' (simplex roman).
  161. ;                   Data type : String.
  162. ;
  163. ;       Def_Color:  The color index to use when no color is specified in
  164. ;                   "Strings".
  165. ;                   The default is (!D.N_COLORS - 1L).
  166. ;                   Data Type : Byte, Int or Long.
  167. ;
  168. ;       Colors:     Normally, color indices can be specified directly in
  169. ;                   "Strings".   If "Colors" is specified, however, then
  170. ;                   "Colors" acts as a translation table to modify the
  171. ;                   actual color index of the text.   For example, when the
  172. ;                   following string is drawn :
  173. ;
  174. ;                      `C13`ABCDEF
  175. ;
  176. ;                   It will be drawn in color index 13 if "Colors" is NOT
  177. ;                   specified.   If "Colors" IS specified then the string
  178. ;                   "ABCDEF" will be drawn in color index Colors(13).
  179. ;
  180. ;                   If "Colors" is specified, and the color number is
  181. ;                   less than zero then Colors(0) is used.   IF the color
  182. ;                   number is greater than or equal to the number of
  183. ;                   elements in "Colors" then Colors(n-1) is used
  184. ;                   (where "n" is the number of elements in "Colors).
  185. ;
  186. ;       W_Erase:    The color index to erase the window with before drawing
  187. ;                   the text.   If "W_Erase" is less than zero then the window
  188. ;                   will NOT be erased first.
  189. ;                   The default is to NOT erase the window first.
  190. ;                   Data Type : Int or Long.
  191. ;
  192. ; RESTRICTIONS:
  193. ;    An IDL window must exist before calling "DISP_TXT" or an error
  194. ;       will result.   All text is drawn in Device coordinates and no 3-D
  195. ;       transformations have any effect.
  196. ;
  197. ; EXAMPLE:
  198. ;       Display a text screen using "DISP_TXT"
  199. ;
  200. ;       ; Create some strings.
  201. ;         strings = STRARR(4)
  202. ;         strings(0) = '0000000000000'
  203. ;         strings(1) = '`F1,C200`'
  204. ;         strings(2) = 'ABC`X200,V-100`DEF`F0`GHIJKL`C155`abc'
  205. ;         strings(3) = '`C255,F1`ABCDEF`F2`GHIJKL'
  206. ;
  207. ;       ; Specify the fonts.
  208. ;         fonts = STRARR(3)
  209. ;         fonts(0) = '*helvetica-bold*--24*|20!5'
  210. ;         fonts(1) = 'vector|15!6'
  211. ;         fonts(2) = '8x13|11!3'
  212. ;
  213. ;       ; Create a window and display the text.
  214. ;         Window, 0
  215. ;         DISP_TXT, strings, fonts, 28, Def_Font='12x24'
  216. ;
  217. ; MODIFICATION HISTORY:
  218. ;       Written by:     Daniel Carr. Tue Sep 29 11:52:56 MDT 1992
  219. ;       Added support for 'Win32' and 'MacOS'
  220. ;                       Daniel Carr. Mon Nov 23 09:44:33 MST 1992
  221. ;       Modified Yspace for 'Win32' and 'MacOS'
  222. ;                       Daniel Carr. Thu Dec 17 17:02:40 MST 1992
  223. ;-
  224.  
  225. PRO Disp_Txt, strings, fonts, yspace, Xstart=xstart, Ystart=ystart, $
  226.               Def_Font=def_font, Def_Style=def_style, Def_Just=def_just, $
  227.               Def_Size=def_size, Def_Color=def_color, Colors=colors, $
  228.               W_Erase=w_erase
  229.  
  230. IF (!D.Window LT 0L) THEN BEGIN
  231.    Print, 'No window exists to draw text in'
  232.    STOP
  233. ENDIF
  234.  
  235. size_strings = Size(strings)
  236. IF (size_strings(size_strings(0)+1) NE 7L) THEN BEGIN
  237.    Print, 'Text array must be of type string'
  238.    STOP
  239. ENDIF
  240. num_strings = N_Elements(strings)
  241.  
  242. size_fonts = Size(fonts)
  243. IF (size_fonts(size_fonts(0)+1) NE 7L) THEN BEGIN
  244.    Print, 'Fonts array must be of type string'
  245.    STOP
  246. ENDIF
  247. num_fonts = N_Elements(fonts)
  248.  
  249. text_space = Fix(yspace(0))
  250.  
  251. default_size = !D.Y_Ch_Size - 1
  252. IF (N_Elements(def_size) GT 0L) THEN default_size = Long(def_size(0))
  253. vector_size = Float(default_size) / ((Float(!D.Y_Ch_Size) + 6.0) / 2.0)
  254.  
  255. default_font = ''
  256. IF (N_Elements(def_font) GT 0L) THEN default_font = String(def_font(0))
  257.  
  258. default_style = '!3'
  259. IF (N_Elements(def_style) GT 0L) THEN default_style = String(def_style(0))
  260.  
  261. default_just = 0.0
  262. IF (N_Elements(def_just) GT 0L) THEN default_just = $
  263.                                      (Float(def_just(0)) > 0.0) < 1.0
  264.  
  265. default_color = !D.N_Colors - 1L
  266. IF (N_Elements(def_color) GT 0L) THEN default_color = Long(def_color(0))
  267.  
  268. t_colors = (-1)
  269. IF (N_Elements(colors) GT 0L) THEN t_colors = (Long(colors) > 0) < $
  270.                                               (!D.N_Colors - 1L)
  271. num_colors = N_Elements(t_colors)
  272.  
  273. erase_col = (-1)
  274. IF (N_Elements(w_erase) GT 0L) THEN erase_col = Long(w_erase(0)) < $
  275.                                                 (!D.N_Colors - 1L)
  276.  
  277. xpos = ((!D.X_Size - (2 * default_size)) * default_just) + default_size
  278. ypos = !D.Y_Size - (text_space + default_size)
  279. IF ((!Version.Os EQ 'Win32') OR (!Version.Os EQ 'MacOS')) THEN BEGIN
  280.    text_space = Fix(4.0 * Float(text_space) / 5.0) > 1
  281. ENDIF
  282. IF (text_space LT 0) THEN ypos = (-text_space)
  283.  
  284. IF (N_Elements(xstart) GT 0L) THEN xpos = Fix(xstart(0))
  285. IF (N_Elements(ystart) GT 0L) THEN ypos = Fix(ystart(0))
  286.  
  287. font_type = 0
  288. fontnum = 0
  289. Device, Font=default_font, Get_Fontnum=fontnum
  290.  
  291. control_delim = '`'
  292. field_delim = ','
  293. option_delim = '|'
  294. style_delim = '!'
  295.  
  296. IF (erase_col GE 0L) THEN Erase, erase_col
  297.  
  298. count = 0L
  299. WHILE ((count LT num_strings) AND $
  300.       ((ypos GE 0) AND (ypos LT !D.Y_Size))) DO BEGIN
  301.    string_len = Strlen(strings(count))
  302.  
  303.    Xyouts, xpos, ypos, default_style, /Device, Font=(-1), Size=vector_size, $
  304.            Color=default_color, T3d=0, Alignment=default_just
  305.    c_xpos = xpos
  306.  
  307.    new_line = 0B
  308.    cur_pos = 0
  309.    WHILE (cur_pos LE string_len) DO BEGIN
  310.       control_pos_l = Strpos(strings(count), control_delim, cur_pos)
  311.       control_pos_r = Strpos(strings(count), control_delim, (control_pos_l + 1))
  312.       IF (control_pos_r GE cur_pos) THEN $
  313.          draw_string = Strmid(strings(count), cur_pos, $
  314.          (control_pos_l-cur_pos)) $
  315.       ELSE $
  316.          draw_string = Strmid(strings(count), cur_pos, string_len)
  317.  
  318.       cur_pos = cur_pos + Strlen(draw_string)
  319.  
  320.       IF (draw_string NE '') THEN BEGIN
  321.          Xyouts, c_xpos, ypos, draw_string, /Device, Font=font_type, $
  322.                  Size=vector_size, Alignment=default_just, $
  323.                  Color=default_color, T3d=0, Width=t_wide
  324.          c_xpos = c_xpos + Fix(t_wide * Float(!D.X_SIZE) * (1.0 - default_just))
  325.          new_line = 1B
  326.       ENDIF
  327.  
  328.       IF ((control_pos_l GE cur_pos) AND (control_pos_r GE (cur_pos + 1))) $
  329.       THEN BEGIN
  330.          control_string = Strmid(strings(count), (control_pos_l + 1), $
  331.                           (control_pos_r - (control_pos_l + 1)))
  332.          control_len = Strlen(control_string)
  333.  
  334.          control_pos = 0
  335.          WHILE (control_pos LE control_len) DO BEGIN
  336.  
  337.             control_string1 = control_string
  338.             field_pos = Strpos(control_string, field_delim, control_pos)
  339.             IF (field_pos GE control_pos) THEN $
  340.                control_string1 = Strmid(control_string, control_pos, $
  341.                                  (field_pos - control_pos)) $
  342.             ELSE $
  343.                control_string1 = Strmid(control_string, $
  344.                                  control_pos, control_len)
  345.  
  346.             control_len1 = Strlen(control_string1)
  347.             control_pos = control_pos + control_len1
  348.  
  349.             first_char = Strupcase(Strmid(control_string1, 0, 1))
  350.             CASE first_char OF
  351.                 'J': BEGIN
  352.                         just_string = Strmid(control_string1, 1, control_len1)
  353.                         IF (just_string NE '') THEN BEGIN
  354.                            ON_IOERROR, SKIP_JUST
  355.                               temp_just = Float(just_string)
  356.                               default_just = temp_just
  357.                            SKIP_JUST:
  358.                            ON_IOERROR, NULL
  359.                         ENDIF
  360.                      END
  361.                 'X': BEGIN
  362.                         x_string = Strmid(control_string1, 1, control_len1)
  363.                         IF (x_string NE '') THEN BEGIN
  364.                            ON_IOERROR, SKIP_X
  365.                               temp_x = Float(x_string)
  366.                               xpos = temp_x
  367.                               c_xpos = temp_x
  368.                            SKIP_X:
  369.                            ON_IOERROR, NULL
  370.                         ENDIF
  371.                      END
  372.                 'Y': BEGIN
  373.                         y_string = Strmid(control_string1, 1, control_len1)
  374.                         IF (y_string NE '') THEN BEGIN
  375.                            ON_IOERROR, SKIP_Y
  376.                               temp_y = Float(y_string)
  377.                               ypos = temp_y
  378.                            SKIP_Y:
  379.                            ON_IOERROR, NULL
  380.                         ENDIF
  381.                      END
  382.                 'H': BEGIN
  383.                         horiz_string = Strmid(control_string1, 1, control_len1)
  384.                         IF (horiz_string NE '') THEN BEGIN
  385.                            ON_IOERROR, SKIP_HORIZ
  386.                               temp_horiz = Float(horiz_string)
  387.                               c_xpos = c_xpos + temp_horiz
  388.                               xpos = c_xpos
  389.                            SKIP_HORIZ:
  390.                            ON_IOERROR, NULL
  391.                         ENDIF
  392.                      END
  393.                 'V': BEGIN
  394.                         vert_string = Strmid(control_string1, 1, control_len1)
  395.                         IF (vert_string NE '') THEN BEGIN
  396.                            ON_IOERROR, SKIP_VERT
  397.                               temp_vert = Float(vert_string)
  398.                               ypos = ypos + temp_vert
  399.                            SKIP_VERT:
  400.                            ON_IOERROR, NULL
  401.                         ENDIF
  402.                      END
  403.                 'C': BEGIN
  404.                         color_string = Strmid(control_string1, 1, control_len1)
  405.                         IF (color_string NE '') THEN BEGIN
  406.                            ON_IOERROR, SKIP_COLOR
  407.                               temp_color = Long(color_string)
  408.                               IF (t_colors(0) GE 0L) THEN $
  409.                                  default_color = t_colors((temp_color > 0L) < $
  410.                                                          (num_colors - 1L)) $
  411.                               ELSE $
  412.                                  default_color = (temp_color > 0L) < $
  413.                                                  (!D.N_Colors - 1L)
  414.                            SKIP_COLOR:
  415.                            ON_IOERROR, NULL
  416.                         ENDIF
  417.                      END
  418.                 'F': BEGIN
  419.                         font_string = Strmid(control_string1, 1, control_len1)
  420.                         font_index = 0L
  421.                         IF (font_string NE '') THEN BEGIN
  422.                            ON_IOERROR, SKIP_FONT
  423.                               temp_index = Long(font_string) > 0L
  424.                               font_index = temp_index
  425.                            SKIP_FONT:
  426.                            ON_IOERROR, NULL
  427.                            IF (font_index GE num_fonts) THEN font_index = 0L
  428.  
  429.                            font_string1 = fonts(font_index)
  430.                            font_string2 = ''
  431.                            option_pos = Strpos(fonts(font_index), option_delim)
  432.                            IF (option_pos GE 0) THEN BEGIN
  433.                               font_string1 = Strmid(fonts(font_index), 0, $
  434.                                              option_pos)
  435.                               font_string2 = Strmid(fonts(font_index), $
  436.                                              (option_pos+1), $
  437.                                              Strlen(fonts(font_index)))
  438.                            ENDIF
  439.  
  440.                            fontnum = 0
  441.                            Device, Font=font_string1, Get_Fontnum=fontnum
  442.                            IF (fontnum GT 0) THEN BEGIN
  443.                               Device, Font=font_string1
  444.                               font_type = 0
  445.                            ENDIF ELSE BEGIN
  446.                               font_type = (-1)
  447.                               IF (font_string2 NE '') THEN BEGIN
  448.                                  style_pos = Strpos(font_string2, style_delim)
  449.                                  y_size_string = Strmid(font_string2, 0, $
  450.                                                         style_pos)
  451.                                  style_string = Strmid(font_string2, $
  452.                                                 style_pos, Strlen(font_string2))
  453.  
  454.                                  IF (y_size_string NE '') THEN BEGIN
  455.                                     ON_IOERROR, SKIP_SIZE
  456.                                        temp_size = Fix(y_size_string)
  457.                                        default_size = temp_size
  458.                                     SKIP_SIZE:
  459.                                     ON_IOERROR, NULL
  460.                                  ENDIF
  461.                                  vector_size = Float(default_size) / $
  462.                                                ((Float(!D.Y_Ch_Size) + 6.0) / $
  463.                                                2.0)
  464.  
  465.                                  IF (style_string NE '') THEN BEGIN
  466.                                     Xyouts, c_xpos, ypos, style_string, $
  467.                                             /Device, $
  468.                                             Font=font_type, Size=vector_size, $
  469.                                             Color=default_color, T3d=0, $
  470.                                             Width=t_wide, Alignment=default_just
  471.                                     c_xpos = c_xpos + $
  472.                                              Fix(t_wide * Float(!D.X_SIZE) * $
  473.                                              (1.0 - default_just))
  474.                                  ENDIF
  475.                               ENDIF
  476.                               vector_size = Float(default_size) / $
  477.                                             ((Float(!D.Y_Ch_Size) + 6.0) / 2.0)
  478.                            ENDELSE
  479.                         ENDIF
  480.                      END
  481.                ELSE:
  482.             ENDCASE
  483.             control_pos = control_pos + 1
  484.          ENDWHILE
  485.  
  486.          cur_pos = cur_pos + control_len + 2
  487.       ENDIF ELSE BEGIN
  488.          cur_pos = cur_pos + 1
  489.       ENDELSE
  490.  
  491.    ENDWHILE
  492.  
  493.    shift_down = text_space
  494.    IF ((!Version.Os EQ 'Win32') OR (!Version.Os EQ 'MacOS')) THEN $
  495.       shift_down = Fix(4.0 * Float(text_space) / 5.0) > 1
  496.  
  497.    IF (new_line) THEN ypos = ypos - shift_down
  498.  
  499.    count = count + 1L
  500. ENDWHILE
  501.  
  502. Empty
  503.  
  504. RETURN
  505. END
  506.